package com.zmq.controller;

import com.zmq.bean.MenuBean;
import com.zmq.service.menu.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 添加目录
     * @param menuBean
     * @return
     */
    @RequestMapping("addMenu")
    public Map addMenu(MenuBean menuBean){
        Map map = new HashMap();
        int i = menuService.addMenu(menuBean);
        if(i>0){
            map.put("code",true);
            map.put("msg","成功！");
        }else{
            map.put("code",false);
            map.put("msg","失败！");
        }
        return map;
    }

    /**
     * 删除目录
     * @param menuBean
     * @return
     */
    @RequestMapping("deleteMenu")
    public Map deleteMenu(MenuBean menuBean){
        Map map = new HashMap();
        int i = menuService.deleteMenu(menuBean);
        if(i>0){
            map.put("code",true);
            map.put("msg","成功！");
        }else{
            map.put("code",false);
            map.put("msg","失败！");
        }
        return map;
    }

    /**
     * 修改目录
     * @param menuBean
     * @return
     */
    @RequestMapping("updateMenu")
    public Map updateMenu(MenuBean menuBean){
        Map map = new HashMap();
        int i = menuService.updateMenu(menuBean);
        if(i>0){
            map.put("code",true);
            map.put("msg","成功！");
        }else{
            map.put("code",false);
            map.put("msg","失败！");
        }
        return map;
    }

    /**
     * 展示目录树
     * @return
     */
    @RequestMapping("queryMenu")
    public Map<String,Object> queryMenu(){
        Map<String,Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> list = menuService.queryMenu();
        map.put("code",true);
        map.put("data",list);
        return map;
    }
}
